package cn.edu.scau.cmi.wujiaxian.comprehensive.dao;

import java.io.PrintWriter;
import java.util.ArrayList;

import cn.edu.scau.cmi.wujiaxian.comprehensive.model.Clazz;
import cn.edu.scau.cmi.wujiaxian.comprehensive.model.Course;
import cn.edu.scau.cmi.wujiaxian.comprehensive.model.ScoreInterval;
import cn.edu.scau.cmi.wujiaxian.comprehensive.model.Student;
import cn.edu.scau.cmi.wujiaxian.comprehensive.model.Teacher;
import cn.edu.scau.cmi.wujiaxian.comprehensive.util.IOFactory;

public class SaveScoreRecord {
	
	public void save(ArrayList<Student> students, Course course, 
			Teacher teacher, Clazz clazz, ArrayList<ScoreInterval> scoreIntervals) {
		String path = "src\\cn\\edu\\scau\\cmi\\wujiaxian\\comprehensive\\database\\scoreRecord.txt";
		PrintWriter out = IOFactory.getPrintWriter(path, "UTF-8");
		out.println("期末考试成绩单");
		out.println("课程：" + course.getName());
		out.println("教师：" + teacher.getName());
		out.println("班级：" + clazz.getGraceAndMajorAndClazz());
		out.println("学号                              |姓名       |考勤       |测验       |作业      |期末      |总评      ");
		for (Student student :students) {
			out.println(student.getStudentNumber()
					+ "|" + student.getName() 
					+ "|" + student.getScore().getAttendanceScore() 
					+ "|" + student.getScore().getTestScore() 
					+ "|" + student.getScore().getWorkScore() 
					+ "|" + student.getScore().getFinalScore() 
					+ "|" + student.getScore().getTotalScore() );
		}
		out.println("成绩区间  | 人数  | 百分比 ");
		for (ScoreInterval scoreInterval : scoreIntervals) {
			out.println(scoreInterval.getScoreInterval() 
					+ "|" + scoreInterval.getNumber()
					+ "|" + String.format("%.2f",scoreInterval.getPercentage() * 100) + "%");
		}
		out.flush();
		out.close();
	}
	
}
